package com.guaju.yueshangLife.widget;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.activity.MainActivity;
import com.guaju.yueshangLife.activity.RefundRequestActivity;
import com.guaju.yueshangLife.databinding.ItemAddPicBinding;
import com.guaju.yueshangLife.utils.FileUtils;
import com.guaju.yueshangLife.utils.ToastUtil;
import com.lljjcoder.style.citylist.Toast.ToastUtils;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.ui.ImageGridActivity;

import java.io.File;
import java.util.ArrayList;

import kr.co.namee.permissiongen.PermissionGen;

public class AddPicItem extends FrameLayout {

    private static final int REQUEST_PERMISSION = 1001;
    public static final int REQUEST_SELECT_IMAGES_CODE11 = 1001;
    public static final int REQUEST_SELECT_IMAGES_CODE12 = 1002;
    public static final int REQUEST_SELECT_IMAGES_CODE13 = 1003;
    public static final int REQUEST_SELECT_IMAGES_CODE21 = 2001;
    public static final int REQUEST_SELECT_IMAGES_CODE22 = 2002;
    public static final int REQUEST_SELECT_IMAGES_CODE23 = 2003;
    public static final int REQUEST_SELECT_IMAGES_CODE31 = 3001;
    public static final int REQUEST_SELECT_IMAGES_CODE32 = 3002;
    public static final int REQUEST_SELECT_IMAGES_CODE33 = 3003;
    private File cameraSavePath;//拍照照片路径
    private Uri uri;//照片uri
    private LayoutInflater layoutInflater;
    private ItemAddPicBinding binding;


    public AddPicItem(Context context) {
        super(context);
        init();
    }


    public AddPicItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        layoutInflater = LayoutInflater.from(getContext());
        binding = DataBindingUtil.inflate(layoutInflater, R.layout.item_add_pic, null, false);
        addView(binding.getRoot());

    }


    public void addImage(String imageUrl) {
        Log.e("guajujerry", "addImage: " + imageUrl);
//        Uri parse = Uri.parse(imageUrl);
//        String filePath = FileUtils.getFilePath(getContext(), parse);
        File file = new File(imageUrl);
        Uri uri = Uri.fromFile(file);
        binding.sdv.setImageURI(uri);
        binding.sdv.setVisibility(View.VISIBLE);
        binding.addicon.setVisibility(View.GONE);
        binding.tvAdd.setVisibility(View.GONE);
    }


}
